package main;


import java.util.Iterator;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import utils.HibernateUtil;
import entity_beans.City;

public class Example1 {

  /**
   * @param args
   */
  public static void main(String[] args) throws Exception {
    /** Getting the Session Factory and session */
//    SessionFactory session = HibernateUtil.getSessionFactory();
//    Session sess = session.getCurrentSession();
    
    Session sess = HibernateUtil.getSession();
    
    /** Starting the Transaction */
    Transaction tx = sess.beginTransaction();
    /** Creating Pojo */
 /*   
    City pojo = new City();
    pojo.setId("3");
    pojo.setName("XYZ");

//    sess.save(pojo);
    
    Query q = sess.getNamedQuery("all_cities");
    Iterator it = q.iterate();
    while (it.hasNext()) {
    	System.out.println(it.next());
    }
 */   
    /** Commiting the changes */
    tx.commit();
    System.out.println("Record Inserted");  
    /** Closing Session */
//    session.close();
    sess.close();
  }

}